package com.hdaccp.ch07

import org.apache.spark.sql.{SaveMode, SparkSession}

object Demo1 {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("ch07Demo1App")
      .getOrCreate()

    import spark.implicits._

    val rdd = spark.sparkContext.textFile("F:/accp教学/sparkresources/music1.txt")

    //rdd=> dataframe

    val accessDF = rdd.map(x=>x.split("\t")).map(y=>Music(y(0),y(1),y(2),y(3),y(4),y(5))).toDF()

    //txt文件=> parqut文件
    //
    accessDF.coalesce(1).write.format("parquet").mode(SaveMode.Overwrite)
      .save("F:/accp教学/sparkresources/clean7")

    spark.stop()
  }

  //封装文件的

}




